package com.clms.system.controller;

import com.clms.common.R;
import com.clms.system.mapper.UserMapper;
import com.clms.system.myconfig.LogAnnotation;
import com.clms.system.pojo.entitry.SysUser;
import com.clms.system.pojo.util.OssUtil;
import com.clms.system.pojo.vo.EqualVo;
import com.clms.system.pojo.vo.OnlyoneVo;
import com.clms.system.pojo.vo.UserVo;
import com.clms.system.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.Map;

/**
 * @program: clms-third
 * @description:
 * @author: 大鱼
 * @create: 2021-07-19 16:20
 **/
@RestController
@RequestMapping("/system/user")
//@CrossOrigin
@Api(value = "用户控制类")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("查询用户")
    @PostMapping("/initUerTable/{currentPage}/{pageSize}")
    public R usertable(@ApiParam("获取分页数") @PathVariable("currentPage") Integer currentPage, @ApiParam("封装前台搜索条件") @PathVariable("pageSize") Integer pageSize, @RequestBody UserVo userVo) {
        return userService.findAllUserPage(currentPage, pageSize, userVo);
    }
    @ApiOperation(value = "更新用户状态")
    @LogAnnotation(title = "更新用户")
    @GetMapping("updataUserStatus/{userId}/{status}")
    public R updataUserStatus(@PathVariable("userId") Integer userId, @PathVariable("status") Integer status) {
        return userService.updataUserStatus(userId, status);
    }
    @ApiOperation(value = "删除用户")
    @LogAnnotation(title = "删除用户")
    @DeleteMapping("deleteuserbyid/{roleId}")
    public R deleteUserById(@PathVariable("roleId") Integer roleId) {
        return userService.deleteUserById(roleId);
    }
    @ApiOperation(value = "更新用户表")
    @LogAnnotation(title = "更新用户表")
    @PostMapping("addorupadte")
    public R userAddOrUpdate(@RequestBody SysUser userinfo) {
        return userService.userAddOrUpdate(userinfo);
    }
    @ApiOperation(value = "获取用户信息")
    @LogAnnotation(title = "获取用户信息")
    @GetMapping("/getuserbyid/{userId}")
    public R getUserById(@PathVariable("userId") Integer userId) {
        return userService.getUserById(userId);
    }
    @ApiOperation(value = "唯一性校验")
    @LogAnnotation(title = "唯一性")
    @PostMapping("onlyonecheck/byname")
    public R Checkbyname(@RequestBody OnlyoneVo map) {
        return userService.Checkbyname(map);
    }
    @ApiOperation(value = "重置密码")
    @LogAnnotation(title = "重置密码")
    @GetMapping("resetbyid/{userid}")
    public R resetById(@PathVariable("userid") String userId) {
        return userService.resetById(userId);
    }
    @ApiOperation(value = "上传头像")
    @LogAnnotation(title = "上传图片")
    @PostMapping("updataimg")
    public R upload(MultipartFile file) {
        try {
            String upload = OssUtil.upload(file.getInputStream(), file.getOriginalFilename());
            System.out.println(upload);
            return R.ok().put("avatar", upload);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return R.error();
    }
    @ApiOperation(value = "更新")
    @PostMapping("updatauserimg")
    public R updataUserImg(@RequestBody SysUser user) {
        return userService.updataUserImg(user);
    }

    @ApiOperation(value = "确认当前用户密码")
    @PostMapping("exituser")
    public R exitUser(@RequestBody SysUser user) {
        return userService.exitUser(user);
    }

    @ApiOperation(value = "更改当前用户密码")
    @PostMapping("changepassword")
    public R changePassword(@RequestBody SysUser user) {
        return userService.changePassword(user);
    }
    @ApiOperation(value = "忘记密码查询Id")
    @PostMapping("/forget/selectuserId")
    public R selectUserIdByName(@RequestBody UserVo userVo) {
        return userService.selectUserIdByName(userVo);
    }
    @ApiOperation(value = "更新密码")

    @PostMapping("/forget/changeforgetpsw")
    public R updataForgetPsw(@RequestBody SysUser sysUser) {
        return userService.updataForgetPsw(sysUser);
    }
    @ApiOperation(value = "验证手机号")

    @GetMapping("/forget/sendsms/{phone}")
    public R sendSms(@PathVariable("phone") String phone) {
        return userService.sendSms(phone);
    }
    @ApiOperation(value = "验证码对比")

    @PostMapping("/forget/equalcode")
    public R equalCode(@RequestBody EqualVo equalVo) {
        return userService.equalCode(equalVo);
    }
}
